﻿using System.Collections.Generic;
using UnityEngine;
using Yoozoo.Core.Extensions.Engine;

namespace Yoozoo.Gameplay.City
{
    public class CityRealAiPoolManager
    {
        private Queue<GameObject> _eventPointObjPool;

        public void OnInitialize()
        {
            _eventPointObjPool = new Queue<GameObject>();
        }

        public GameObject GetPointObj()
        {
            GameObject result = null;
            if (_eventPointObjPool.Count > 0)
            {
                result = _eventPointObjPool.Dequeue();
            }
            else
            {
                result = new GameObject();
            }
            
            return result;
        }

        public void ReturnPointObj(GameObject pointObj)
        {
            pointObj.SetParent(CityRealAiManager.GetInstance().CityRealAiRootTran);
            _eventPointObjPool.Enqueue(pointObj);
        }

        public void OnDispose()
        {
            if (_eventPointObjPool != null)
            {
                while (_eventPointObjPool.Count > 0)
                {
                    var obj = _eventPointObjPool.Dequeue();
                    Object.Destroy(obj);
                }
            }
        }
    }
}